#include "LWinSock.h"

LWinSock::LWinSock():m_Run(false)
{

}

LWinSock::~LWinSock()
{
	Cleanup();
}

#define ALLREADY_RUN -10086

int LWinSock::Startup()
{
	if(m_Run){return ALLREADY_RUN;}

	WSADATA wsaData;
	int ret = WSAStartup(MAKEWORD(2,2), &wsaData);
	m_Run = ret == 0 ? true : false;
	return ret;
}

void LWinSock::Cleanup()
{
	if(!m_Run){return;}

	WSACleanup();
	m_Run = false;
}

SOCKET LWinSock::TCPSocket()
{
	return socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
}

void  LWinSock::SetSockAddrInfo(sockaddr_in* info,const char* ip,int port)
{
	ZeroMemory(info,sizeof(sockaddr_in));
	info->sin_family = AF_INET;
	info->sin_addr.s_addr = inet_addr(ip);
	info->sin_port = htons(port);
}